package itheima.ZuoYe02;

public class Demo {
   public static int a = 0;

    public static void main(String[] args) throws InterruptedException {
    Object obj = new Object();
    new Thread(){
        @Override
        public void run() {
            synchronized (obj){
                for (int i = 0; i < 1000; i++) {
                    if (i%2==0 && i%3==0 && i%5==0 && i%7==0){
                        try {
                            obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    obj.notify();
                }
            }
        }
    }.start();
    new Thread(){
        @Override
        public void run() {
            while (true) {
                synchronized (obj) {
                    try {
                        obj.notify();
                        System.out.println(++a);
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }.start();
    Thread.sleep(2000);
        System.out.println(a);
    }
}
